#include "stdafx.h"
#include "PauseState.h"
#include "TextureManager.h"
#include "BMPText.h"
#include "MainMenuState.h"
#include "BitmapTextObject.h"
#include "DirectInput.h"
#include "SelectSpellState.h"

PauseState::PauseState()
{	

}

PauseState::~PauseState()
{

}

#define CURSOR_X 300
#define CURSOR_Y_SPACING 150
void PauseState::Init()
{
	m_nPauseMenuOption = PAUSE_MENU_PLAY;

	//Three bitmap font options
	BitmapTextObject* pObject = new BitmapTextObject();

	pObject->SetText(BIG_FONT, "RESUME", D3DXVECTOR2(CURSOR_X,100));
	m_pPauseOptions[0] = pObject;
	ObjectManager::GetInstance()->AddObject(pObject);

	pObject = new BitmapTextObject();
	pObject->SetText(BIG_FONT, "SPELLS", D3DXVECTOR2(CURSOR_X,250));
	m_pPauseOptions[1] = pObject;
	ObjectManager::GetInstance()->AddObject(pObject);

	pObject = new BitmapTextObject();
	pObject->SetText(BIG_FONT, "OPTIONS", D3DXVECTOR2(CURSOR_X,400));
	m_pPauseOptions[2] = pObject;
	ObjectManager::GetInstance()->AddObject(pObject);

	pObject = new BitmapTextObject();
	pObject->SetText(BIG_FONT, "EXIT", D3DXVECTOR2(CURSOR_X,550));
	m_pPauseOptions[3] = pObject;
	ObjectManager::GetInstance()->AddObject(pObject);

	for (int i = 0; i < MAIN_MENU_TOTAL_OPTIONS; ++i)
		SAFE_RELEASE(m_pPauseOptions[i]);

	BaseObject2D* pCursor = new BaseObject2D();
	pCursor->SetTextureID(TextureManager::GetInstance()->LoadTexture("resources\\arrow.png"));

	ObjectManager::GetInstance()->AddObject(pCursor);
	pCursor->SetPosition(CURSOR_X,100);
	pCursor->SetScale(0.35f, 0.35f);
	m_pCursor = pCursor;
	SAFE_RELEASE(pCursor);
}

void PauseState::Update(float _dt)
{
	if(DirectInput::GetInstance()->KeyPressed(DIK_UP))
	{
		if(m_nPauseMenuOption == 0)
		{
			m_nPauseMenuOption = PAUSE_MENU_TOTAL_OPTIONS-1;
			m_pCursor->SetPosition(CURSOR_X, 550);
		}
		else
		{
			m_nPauseMenuOption -= 1;
			m_pCursor->SetPosition(CURSOR_X, m_pCursor->GetPosition().y - CURSOR_Y_SPACING);
		}
	}
	if(DirectInput::GetInstance()->KeyPressed(DIK_DOWN))
	{
		if(m_nPauseMenuOption == PAUSE_MENU_TOTAL_OPTIONS-1)
		{
			m_nPauseMenuOption = 0;
			m_pCursor->SetPosition(CURSOR_X, CURSOR_Y_SPACING);
		}
		else
		{
			m_nPauseMenuOption += 1;
			m_pCursor->SetPosition(CURSOR_X, m_pCursor->GetPosition().y + CURSOR_Y_SPACING);
		}
	}

	if(DirectInput::GetInstance()->KeyPressed(DIK_RETURN))
	{
		switch(m_nPauseMenuOption)
		{
		case PAUSE_MENU_PLAY:
			{
				StateManager::GetInstance()->Pop();
				break;
			}
		case PAUSE_MENU_SPELLS:
			{
				StateManager::GetInstance()->ChangeState(SelectSpellState::GetInstance());
				break;
			}
		case PAUSE_MENU_OPTIONS:
			{
				//Intro for now
				//StateManager::GetInstance()->ChangeState(IntroState::GetInstance());
				break;
			}
		case PAUSE_MENU_EXIT:
			{
				StateManager::GetInstance()->ChangeState(MainMenuState::GetInstance(), true);
				break;
			}
		}
	}
}

void PauseState::Render()
{
	ObjectManager::GetInstance()->RenderObjects();
}

void PauseState::Shutdown()
{
	for(int i = 0; i < PAUSE_MENU_TOTAL_OPTIONS; ++i)
		ObjectManager::GetInstance()->RemoveObject(m_pPauseOptions[i]);

	ObjectManager::GetInstance()->RemoveObject(m_pCursor);
}